package com.yuanxing;

public class Test {

    public static void main(String[] args) {
        // 深拷贝
        Dog1 dog = new Dog1();
        dog.setName("tom");
        dog.setColor("黑白");
        dog.setAge(1);
        Dog1 dog1 = new Dog1();
        dog1.setName("jerry");
        dog.setFriend(dog1);

        System.out.println(dog);
        Dog1 dog11 = ObjClone.cloneObj(dog);
        System.out.println(dog11);

        System.out.println("*****************");
        dog11.getFriend().setName("jerry12");
        System.out.println(dog11);//
        System.out.println(dog);// jerry




    }

    public static void aaa(){
        // 有一只狗狗，一岁了，黑白色，名字叫做tom, 有一个小狗朋友叫jerry  想克隆一只狗狗
        Dog dog = new Dog();
        dog.setName("tom");
        dog.setColor("黑白");
        dog.setAge(1);
        Dog dog1 = new Dog();
        dog1.setName("jerry");
        dog.setFriend(dog1);

        System.out.println(dog);

        try {
            System.out.println("----");
            Dog clone = dog.clone();
            System.out.println(clone);

            System.out.println("***********************");
            // clone.setName("test");
            //  dog 名字是: tom  test
            //

           // 更改了克隆的狗的朋友  jerry12
            clone.getFriend().setName("jerry12");

            System.out.println(clone);
            //
            System.out.println(dog);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }


    }

}
